package com.spi.soconversion.base.definition;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.spi.soconversion.orders.conversion.SalvageLine;

public class OpenSalesOrderDefinition {
	
	// Order Attributes
	private String billToID;	
	private String billToKey;
	private String documentType;
	private String enterpriseCode = "BAY";
	private String entryType = "STORE";
	private String orderDate;
	private String orderName;
	private String orderNo;
	private String paymentStatus = "";
	private String sellerOrganizationCode;	
	private String shipToID;
	private String shipToKey;
	private String taxExemptFlag;
	private String taxExemptCertificate;
	
	// Order Definition
	private OrderExtension orderExtn = new OrderExtension();
	private List<OrderLine> orderLinesList = new ArrayList<OrderLine>();
	private PersonInfoShipTo personInfoShipTo = new PersonInfoShipTo();
	private PersonInfoBillTo personInfoBillTo = new PersonInfoBillTo();
	private List<ProductServiceAssoc> productServiceAssocList = new ArrayList<ProductServiceAssoc>();
	private List<OrderLineRelationShip> orderLineRelationshipList = new ArrayList<OrderLineRelationShip>();
	private List<HeaderCharge> headerChargesList = new ArrayList<HeaderCharge>();
	private List<HeaderTax> headerTaxesList = new ArrayList<HeaderTax>();	
	
	private List<SalvageLine> salvageOrderLinesList = new ArrayList<SalvageLine>();
	private List<OrderLine> nonFurnitureWTYLinesList = new ArrayList<OrderLine>();
	private List<OrderLine> furnitureWTYLinesList = new ArrayList<OrderLine>();
	private List<OrderLine> furnitureWRFEELinesList = new ArrayList<OrderLine>();
	
	public boolean addWFREELine(OrderLine lc) {
		boolean status = false;
		if (!furnitureWRFEELinesList.contains(lc)) {
			status = furnitureWRFEELinesList.add(lc);
		}
		return status;
	}

	public boolean removeWFREELine(OrderLine lc) {
		boolean status = false;
		status = furnitureWRFEELinesList.remove(lc);
		return status;
	}

	public List<OrderLine> getWFREELinesList() {
		return furnitureWRFEELinesList;
	}	

	public boolean addNonFurnitureWtyLine(OrderLine lc) {
		boolean status = false;
		if (!nonFurnitureWTYLinesList.contains(lc)) {
			status = nonFurnitureWTYLinesList.add(lc);
		}
		return status;
	}

	public boolean removeNonFurnitureWtyLine(OrderLine lc) {
		boolean status = false;
		status = furnitureWTYLinesList.remove(lc);
		return status;
	}

	public List<OrderLine> getNonFunitureWtyLinesList() {
		return nonFurnitureWTYLinesList;
	}	
	
	public boolean addFurnitureWtyLine(OrderLine lc) {
		boolean status = false;
		if (!furnitureWTYLinesList.contains(lc)) {
			status = furnitureWTYLinesList.add(lc);
		}
		return status;
	}

	public boolean removeFurnitureWtyLine(OrderLine lc) {
		boolean status = false;
		status = furnitureWTYLinesList.remove(lc);
		return status;
	}

	public List<OrderLine> getFunitureWtyLinesList() {
		return furnitureWTYLinesList;
	}	

	public boolean addSalvageLine(SalvageLine lc) {
		boolean status = false;
		if (!salvageOrderLinesList.contains(lc)) {
			status = salvageOrderLinesList.add(lc);
		}
		return status;
	}

	public boolean removeSalvage(SalvageLine lc) {
		boolean status = false;
		status = salvageOrderLinesList.remove(lc);
		return status;
	}

	public List<SalvageLine> getSalvageLineList() {
		return salvageOrderLinesList;
	}

	public boolean addOrderLineRelationShip(OrderLineRelationShip orderLineRelationShip) {
		boolean status = false;
		if (!orderLineRelationshipList.contains(orderLineRelationShip)) {
			status = orderLineRelationshipList.add(orderLineRelationShip);
		}
		return status;
	}

	public boolean removeOrderLineRelationShip(OrderLineRelationShip orderLineRelationShip) {
		boolean status = false;
		status = orderLineRelationshipList.remove(orderLineRelationShip);
		return status;
	}

	public boolean addProductServiceAssoc(ProductServiceAssoc productServiceAssoc) {
		boolean status = false;
		if (!productServiceAssocList.contains(productServiceAssoc)) {
			status = productServiceAssocList.add(productServiceAssoc);
		}
		return status;
	}

	public boolean removeProductServiceAssoc(ProductServiceAssoc productServiceAssoc) {
		boolean status = false;
		status = productServiceAssocList.remove(productServiceAssoc);
		return status;
	}

	public boolean addHeaderCharge(HeaderCharge lc) {
		boolean status = false;
		if (!headerChargesList.contains(lc)) {
			status = headerChargesList.add(lc);
		}
		return status;
	}

	public boolean removeHeaderCharge(HeaderCharge lc) {
		boolean status = false;
		status = headerChargesList.remove(lc);
		return status;
	}

	public List<HeaderCharge> getHeaderChargeList() {
		return headerChargesList;
	}
	
	public boolean addHeaderTax(HeaderTax lc) {
		boolean status = false;
		if (!headerTaxesList.contains(lc)) {
			status = headerTaxesList.add(lc);
		}
		return status;
	}

	public boolean removeHeaderTax(HeaderTax lc) {
		boolean status = false;
		status = headerTaxesList.remove(lc);
		return status;
	}

	public List<HeaderTax> getHeaderTaxList() {
		return headerTaxesList;
	}	
	
	public boolean addOrderLine(OrderLine lc) {
		boolean status = false;
		if (!orderLinesList.contains(lc)) {
			status = orderLinesList.add(lc);
		}
		return status;
	}

	public boolean removeOrderLine(OrderLine lc) {
		boolean status = false;
		status = orderLinesList.remove(lc);
		return status;
	}

	public List<OrderLine> getOrderLineList() {
		return orderLinesList;
	}
			
	public OrderLine getOrderLine(int i) {
		return orderLinesList.get(i);
	}
	
	public OrderLine[] getOrderLineArray() {
		OrderLine[] result = new OrderLine[orderLinesList.size()];
		orderLinesList.toArray(result);
		return result;
	}

	public ProductServiceAssoc[] getProductServiceAssocArray() {
		ProductServiceAssoc[] result = new ProductServiceAssoc[productServiceAssocList.size()];
		productServiceAssocList.toArray(result);
		return result;
	}

	public OrderLineRelationShip[] getOrderLineRelationshipArray() {
		OrderLineRelationShip[] result = new OrderLineRelationShip[orderLineRelationshipList.size()];
		orderLineRelationshipList.toArray(result);
		return result;
	}

	public HeaderCharge[] getHeaderChargeArray() {
		HeaderCharge[] result = new HeaderCharge[headerChargesList.size()];
		headerChargesList.toArray(result);
		return result;
	}
	
	public HeaderTax[] getHeaderTaxArray() {
		HeaderTax[] result = new HeaderTax[headerTaxesList.size()];
		headerTaxesList.toArray(result);
		return result;
	}
			
	public OrderExtension getOrderExtn() {
		return orderExtn;
	}

	public void setOrderExtn(OrderExtension orderExtn) {
		this.orderExtn = orderExtn;
	}

	public PersonInfoShipTo getPersonInfoShipTo() {
		return personInfoShipTo;
	}

	public void setPersonInfoShipTo(PersonInfoShipTo personInfoShipTo) {
		this.personInfoShipTo = personInfoShipTo;
	}

	public PersonInfoBillTo getPersonInfoBillTo() {
		return personInfoBillTo;
	}

	public void setPersonInfoBillTo(PersonInfoBillTo personInfoBillTo) {
		this.personInfoBillTo = personInfoBillTo;
	}

	public String getBillToID() {
		return billToID;
	}
	
	public void setBillToID(String billToID) {
		this.billToID = billToID;
	}
	
	public String getDocumentType() {
		return documentType;
	}
	
	public void setDocumentType(String documentType) {
		this.documentType = documentType;
	}
	
	public String getEnterpriseCode() {
		return enterpriseCode;
	}
	
	public void setEnterpriseCode(String enterpriseCode) {
		this.enterpriseCode = enterpriseCode;
	}
	
	public String getEntryType() {
		return entryType;
	}
	
	public void setEntryType(String entryType) {
		this.entryType = entryType;
	}
	
	public String getOrderDate() {
		return orderDate;
	}
	
	public void setOrderDate(String orderDate) {
		this.orderDate = orderDate;
	}
	
	public String getOrderNo() {
		return orderNo;
	}
	
	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}
	
	public String getSellerOrganizationCode() {
		return sellerOrganizationCode;
	}
	
	public void setSellerOrganizationCode(String sellerOrganizationCode) {
		this.sellerOrganizationCode = sellerOrganizationCode;
	}
	
	public List<OrderLine> getOrderLinesList() {
		return orderLinesList;
	}
	
	public void setOrderLinesList(List<OrderLine> orderLinesList) {
		this.orderLinesList = orderLinesList;
	}
	
	public List<HeaderCharge> getHeaderChargesList() {
		return headerChargesList;
	}
	
	public void setHeaderChargesList(List<HeaderCharge> headerChargesList) {
		this.headerChargesList = headerChargesList;
	}
	
	public List<HeaderTax> getHeaderTaxesList() {
		return headerTaxesList;
	}
	
	public void setHeaderTaxesList(List<HeaderTax> headerTaxesList) {
		this.headerTaxesList = headerTaxesList;
	}

	public String getBillToKey() {
		return billToKey;
	}

	public void setBillToKey(String billToKey) {
		this.billToKey = billToKey;
	}

	public String getOrderName() {
		return orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public String getPaymentStatus() {
		return paymentStatus;
	}

	public void setPaymentStatus(String paymentStatus) {
		this.paymentStatus = paymentStatus;
	}

	public String getShipToID() {
		return shipToID;
	}

	public void setShipToID(String shipToID) {
		this.shipToID = shipToID;
	}

	public String getShipToKey() {
		return shipToKey;
	}

	public void setShipToKey(String shipToKey) {
		this.shipToKey = shipToKey;
	}

	public String getTaxExemptFlag() {
		return taxExemptFlag;
	}

	public void setTaxExemptFlag(String taxExemptFlag) {
		this.taxExemptFlag = taxExemptFlag;
	}

	public String getTaxExemptCertificate() {
		return taxExemptCertificate;
	}

	public void setTaxExemptCertificate(String taxExemptCertificate) {
		this.taxExemptCertificate = taxExemptCertificate;
	}

	public List<ProductServiceAssoc> getProductServiceAssocList() {
		return productServiceAssocList;
	}

	public void setProductServiceAssocList(
			List<ProductServiceAssoc> productServiceAssocList) {
		this.productServiceAssocList = productServiceAssocList;
	}

	public List<OrderLineRelationShip> getOrderLineRelationshipList() {
		return orderLineRelationshipList;
	}

	public void setOrderLineRelationshipList(
			List<OrderLineRelationShip> orderLineRelationshipList) {
		this.orderLineRelationshipList = orderLineRelationshipList;
	}		
	
	@Override
	public String toString() {
        StringBuffer s = new StringBuffer();
        s.append("Order[-->"
        			+ getBillToID() + ", "
        			+ getBillToKey() + ", "
        			+ getDocumentType() + ", "
        			+ getEnterpriseCode() + ", "
        			+ getEntryType() + ", "
        			+ getOrderDate() + ", "
        			+ getOrderName() + ", "         			
        			+ getOrderNo() + ", "
        			+ getPaymentStatus() + ", " 
        			+ getSellerOrganizationCode() + ", "
        			+ getShipToKey() + ", "
           			+ getTaxExemptFlag() + ", " 
        			+ getTaxExemptCertificate() + "]");
        
        
        Iterator<OrderLine> itr = orderLinesList.iterator();
        while(itr.hasNext()) {
        	s.append( "\n" + itr.next() + "\n");
        }        
        
        return s.toString();
    }
}